
package com.showcai.controller.certificate;

import com.showcai.controller.base.BaseController;
import com.showcai.controller.base.WeChatBaseController;
import com.showcai.def.Constant;
import com.showcai.module.Organization;
import com.showcai.myRunTime.MyRunTimeExcption;
import com.showcai.result.ResultObj;
import com.showcai.service.CertificateService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

/**
 * Created by lutao on 2017/7/14.
 */
@RequestMapping("/certificate")
@Controller
public class CertificateController extends WeChatBaseController {
 @Autowired
    CertificateService certificateService;

    /**
     * 验证卡券
     *
     * @return
     */
    @RequestMapping(value = "/verifyExperience/{certificateId}", method = RequestMethod.POST)
    @ResponseBody
    public String userGain(@PathVariable String certificateId) {
        ResultObj resultObj = new ResultObj();
        Organization organization=(Organization)session.getAttribute(Constant.SESSION_KEY_ORGANIZATION_USER_LOGIN);
        if(organization==null){
            throw new MyRunTimeExcption("机构没有登录！");
        }
         certificateService.verifyExperience(certificateId,organization.getTid());
        certificateService.usedCertificate(certificateId);
        resultObj.setMsg("操作成功！");

        return resultObj.toJson();
    }

    /**
     * 卡券验证页面
     * @return
     */
    @RequestMapping(value = "/verify")
    public ModelAndView verify() {
        ModelAndView mov = new ModelAndView();
        String views = "certificate/web/verify";
        if (getIsMobile()) {
            views = "certificate/wap/verify";
        }
        mov.setViewName(views);
        return mov;
    }

}
